package com.kly.user.serviceImpl;

import com.alibaba.excel.util.StringUtils;
import com.fqgj.common.api.Response;
import com.fqgj.log.factory.LogFactory;
import com.fqgj.log.interfaces.Log;
import com.kly.user.db.dao.UserDao;
import com.kly.user.db.dbo.MemberBenefitsDBO;
import com.kly.user.dto.MemberBenefitsDto;
import com.kly.user.mapper.MemberBenefitsMapper;
import com.kly.user.service.MemberBenefitsForUserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Objects;

/**
 * 会员权益
 * @author linqu
 */
@Service("memberBenefitsForUserService")
public class MemberBenefitsForUserServiceImpl implements MemberBenefitsForUserService {

    private static Log logger = LogFactory.getLog(MemberBenefitsForUserServiceImpl.class);
    @Resource
    private UserDao userDao;
    @Resource
    private MemberBenefitsMapper memberBenefitsMapper;

    /**
     * 会员权益使用状况
     */
    @Override
    public Response<MemberBenefitsDto> memberUsageDetail(String userCode, Integer days) {
        if (StringUtils.isBlank(userCode)) {
            return Response.ok();
        }
        final MemberBenefitsDBO memberBenefitsDbo = userDao.memberUsageDetail(userCode, days);
        if (Objects.nonNull(memberBenefitsDbo)) {
            return Response.ok(memberBenefitsMapper.toDto(memberBenefitsDbo));
        }
        return Response.ok();
    }
}
